package com.micro.ai.template.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 模板实体（调整后）
 * 对应表：agent_templates
 *
 * @author micro-ai
 * @since 0.0.1
 * @version 2.0 支持多租户
 */
@Data
@TableName(value = "agent_templates", autoResultMap = true)
@Schema(description = "AI Agent模板实体")
public class Template {

    @TableId(value = "id", type = IdType.ASSIGN_ID)
    @Schema(description = "主键ID")
    private String id;

    @TableField("template_id")
    @Schema(description = "模板ID", example = "tpl_1234567890")
    private String templateId;

    @TableField("template_name")
    @Schema(description = "模板名称", example = "智能客服助手")
    private String templateName;

    @TableField("description")
    @Schema(description = "模板描述")
    private String description;

    @TableField("category_id")
    @Schema(description = "分类ID", example = "customer_service")
    private String categoryId;

    // ============================================================================
    // ✅ 多租户和用户关联
    // ============================================================================

    @TableField("tenant_id")
    @Schema(description = "所属租户ID", example = "tenant_001")
    private String tenantId;

    @TableField("created_by")
    @Schema(description = "创建者用户ID", example = "usr_001")
    private String createdBy;

    // ============================================================================
    // 模板基本信息
    // ============================================================================

    @TableField("author")
    @Schema(description = "作者显示名称", example = "张三")
    private String author;

    @TableField("license")
    @Schema(description = "许可证", example = "MIT")
    private String license;

    @TableField("min_system_version")
    @Schema(description = "最低系统版本", example = "1.0.0")
    private String minSystemVersion;

    @TableField("enabled")
    @Schema(description = "是否启用", example = "true")
    private Boolean enabled;

    @TableField("is_public")
    @Schema(description = "是否公开", example = "true")
    private Boolean isPublic;

    @TableField("status")
    @Schema(description = "审核状态", example = "APPROVED", allowableValues = {"DRAFT", "PENDING", "APPROVED", "REJECTED"})
    private String status;

    // ============================================================================
    // 统计信息
    // ============================================================================

    @TableField("view_count")
    @Schema(description = "浏览次数", example = "1250")
    private Integer viewCount;

    @TableField("download_count")
    @Schema(description = "下载次数", example = "350")
    private Integer downloadCount;

    @TableField("use_count")
    @Schema(description = "使用次数", example = "1850")
    private Integer useCount;

    @TableField("rating_score")
    @Schema(description = "评分", example = "4.75")
    private BigDecimal ratingScore;

    @TableField("rating_count")
    @Schema(description = "评分人数", example = "128")
    private Integer ratingCount;

    // ============================================================================
    // JSON字段
    // ============================================================================

    @TableField(value = "tags", typeHandler = JacksonTypeHandler.class)
    @Schema(description = "标签列表", example = "[\"客服\", \"对话\", \"NLP\"]")
    private List<String> tags;

    @TableField("cover_image")
    @Schema(description = "封面图片URL", example = "https://example.com/cover.jpg")
    private String coverImage;

    // ============================================================================
    // 时间戳
    // ============================================================================

    @TableField("created_at")
    @Schema(description = "创建时间", example = "2025-10-25 10:00:00")
    private LocalDateTime createdAt;

    @TableField("updated_at")
    @Schema(description = "更新时间", example = "2025-10-25 15:30:00")
    private LocalDateTime updatedAt;

    @TableField("deleted_at")
    @Schema(description = "删除时间（软删除）")
    private LocalDateTime deletedAt;
}
